<?php

    function find_sort_type($DB, $cat_ID) {

        $res = $DB->query('SELECT sort_TYPE from category WHERE ID=' . $cat_ID)->row_array();

        if (count($res) > 0)
            return $res['sort_TYPE'];
        else
            return "ASC";
    }

    function find_sort_type_by_post($DB, $post_ID) {

        $res = $DB->query('SELECT category_ID from post WHERE ID=' . $post_ID)->row_array();

        if (count($res) > 0)
            return find_sort_type($DB, $res['category_ID']);
        else
            return "ASC";
    }
    